package com.zhoutao.blog.seven.model.converter;

import com.zhoutao.blog.seven.dao.model.ArticleDao;
import com.zhoutao.blog.seven.model.response.Article;
import com.zhoutao.blog.seven.utils.TimeUtils;
import org.springframework.stereotype.Component;

@Component
public class ArticleConverter extends AbstractConverter<ArticleDao, Article> {


    @Override
    public Article converterFrom(ArticleDao articleDao) {
        return new Article().setId(articleDao.getId())
                .setTitle(articleDao.getTitle())
                .setAvatar(articleDao.findAvatar())
                .setKeys(articleDao.getKeys())
                .setType(articleDao.getType())
                .setMkContent(articleDao.getMkContent())
                .setDescription(articleDao.getDescription())
                .setContent(articleDao.getContent())
                .setReadCount(articleDao.getReadCount())
                .setCommentCount(articleDao.getCommentCount())
                .setCategoryId(articleDao.getCategoryId())
                .setIcon(articleDao.getIcon())
                .setCreatedAt(TimeUtils.format(articleDao.getCreatedAt()));
    }

    @Override
    public ArticleDao converterTO(Article article) {
        return new ArticleDao().setId(article.getId())
                .setTitle(article.getTitle())
                .setAvatar(article.getAvatar())
                .setKeys(article.getKeys())
                .setType(article.getType())
                .setIcon(article.getIcon())
                .setMkContent(article.getMkContent())
                .setCategoryId(article.getCategoryId())
                .setDescription(article.getDescription())
                .setContent(article.getContent());
    }
}
